package com.yunwushanhe.controller;



import com.yunwushanhe.annotation.SystemLog;
import com.yunwushanhe.bean.req.MenuSelectReq;
import com.yunwushanhe.bean.req.MenuUpdateReq;
import com.yunwushanhe.bean.ret.ResponseResult;
import com.yunwushanhe.bean.vo.*;
import com.yunwushanhe.entity.Menu;
import com.yunwushanhe.service.MenuService;
import com.yunwushanhe.service.RoleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 菜单权限表(Menu)表控制层
 *
 * @author 抬头看看天
 * @since 2023-08-23 20:43:10
 */
@RestController
@RequestMapping("/system/menu")
public class MenuController {

    @Resource
    private MenuService menuService;
    @Resource
    private RoleService roleService;

    @PostMapping
    @SystemLog(businessName = "增加菜单的接口")
    public ResponseResult<Object> addMenu(@RequestBody Menu Menu){
        return menuService.addMenu(Menu);
    }

    @GetMapping("/list")
    @SystemLog(businessName = "查询所有菜单的接口，不用分页")
    public ResponseResult<List<MenuSelectAllVO>> listAllMenu(MenuSelectReq menuSelectReq){
        return menuService.listAllMenu(menuSelectReq);
    }

    @GetMapping("/{id}")
    @SystemLog(businessName = "根据id查询所有指定菜单信息的接口，用于菜单信息修改回显")
    public ResponseResult<MenuUpdateVO> selectMenuById(@PathVariable("id") Long id){
        return menuService.selectMenuById(id);
    }

    @PutMapping
    @SystemLog(businessName = "更新菜单信息的接口")
    public ResponseResult<Object> updateMenuById(@RequestBody MenuUpdateReq menuUpdateReq){
        return menuService.updateMenuById(menuUpdateReq);
    }

    @DeleteMapping("/{menuId}")
    @SystemLog(businessName = "根据菜单id删除菜单的接口")
    public ResponseResult<Object> deleteMenuById(@PathVariable("menuId") Long id){
        return menuService.deleteMenuById(id);
    }

    @GetMapping("/treeselect")
    @SystemLog(businessName = "获取所有菜单目录层级关系的接口，用于前端进行页面展示")
    public ResponseResult<List<MenuTreeVO>> getMenuTree(){
        return menuService.getMenuTree();
    }

    @GetMapping("/roleMenuTreeselect/{id}")
    @SystemLog(businessName = "加载对应角色菜单列表树接口，获取树的方法是相互调用的")
    public ResponseResult<MenuRoleListVO> getRoleMenuTreeByUserId(@PathVariable("id") Long id){
        return roleService.getRoleMenuTreeByRoleId(id);
    }

}

